<template>
  <el-dialog
    :title="!dataForm.doctorId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="医生姓名
" prop="doctorName">
      <el-input v-model="dataForm.doctorName" placeholder="医生姓名
"></el-input>
    </el-form-item>
    <el-form-item label="医院id外键
" prop="hospitalId">
      <el-input v-model="dataForm.hospitalId" placeholder="医院id外键
"></el-input>
    </el-form-item>
    <el-form-item label="1、普通2、主治
" prop="doctorGrade">
      <el-input v-model="dataForm.doctorGrade" placeholder="1、普通2、主治
"></el-input>
    </el-form-item>
    <el-form-item label="" prop="idImg">
      <el-input v-model="dataForm.idImg" placeholder=""></el-input>
    </el-form-item>
    <el-form-item label="资格证书
" prop="certificate">
      <el-input v-model="dataForm.certificate" placeholder="资格证书
"></el-input>
    </el-form-item>
    <el-form-item label="执业证书
" prop="licence">
      <el-input v-model="dataForm.licence" placeholder="执业证书
"></el-input>
    </el-form-item>
    <el-form-item label="联系方式
" prop="tel">
      <el-input v-model="dataForm.tel" placeholder="联系方式
"></el-input>
    </el-form-item>
    <el-form-item label="审核状态0、待审核1、通过2、未通过
" prop="status">
      <el-input v-model="dataForm.status" placeholder="审核状态0、待审核1、通过2、未通过
"></el-input>
    </el-form-item>
    <el-form-item label="未通过原因
" prop="reason">
      <el-input v-model="dataForm.reason" placeholder="未通过原因
"></el-input>
    </el-form-item>
    <el-form-item label="好评" prop="goodDegree">
      <el-input v-model="dataForm.goodDegree" placeholder="好评"></el-input>
    </el-form-item>
    <el-form-item label="身份证" prop="idCard">
      <el-input v-model="dataForm.idCard" placeholder="身份证"></el-input>
    </el-form-item>
    <el-form-item label="总收入" prop="totalMoney">
      <el-input v-model="dataForm.totalMoney" placeholder="总收入"></el-input>
    </el-form-item>
    <el-form-item label="年限" prop="year">
      <el-input v-model="dataForm.year" placeholder="年限"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          doctorId: 0,
          doctorName: '',
          hospitalId: '',
          doctorGrade: '',
          idImg: '',
          certificate: '',
          licence: '',
          tel: '',
          status: '',
          reason: '',
          goodDegree: '',
          idCard: '',
          totalMoney: '',
          year: ''
        },
        dataRule: {
          doctorName: [
            { required: true, message: '医生姓名
不能为空', trigger: 'blur' }
          ],
          hospitalId: [
            { required: true, message: '医院id外键
不能为空', trigger: 'blur' }
          ],
          doctorGrade: [
            { required: true, message: '1、普通2、主治
不能为空', trigger: 'blur' }
          ],
          idImg: [
            { required: true, message: '不能为空', trigger: 'blur' }
          ],
          certificate: [
            { required: true, message: '资格证书
不能为空', trigger: 'blur' }
          ],
          licence: [
            { required: true, message: '执业证书
不能为空', trigger: 'blur' }
          ],
          tel: [
            { required: true, message: '联系方式
不能为空', trigger: 'blur' }
          ],
          status: [
            { required: true, message: '审核状态0、待审核1、通过2、未通过
不能为空', trigger: 'blur' }
          ],
          reason: [
            { required: true, message: '未通过原因
不能为空', trigger: 'blur' }
          ],
          goodDegree: [
            { required: true, message: '好评不能为空', trigger: 'blur' }
          ],
          idCard: [
            { required: true, message: '身份证不能为空', trigger: 'blur' }
          ],
          totalMoney: [
            { required: true, message: '总收入不能为空', trigger: 'blur' }
          ],
          year: [
            { required: true, message: '年限不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.doctorId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.doctorId) {
            this.$http({
              url: this.$http.adornUrl(`/doctor/doctormessage/info/${this.dataForm.doctorId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.doctorName = data.doctorMessage.doctorName
                this.dataForm.hospitalId = data.doctorMessage.hospitalId
                this.dataForm.doctorGrade = data.doctorMessage.doctorGrade
                this.dataForm.idImg = data.doctorMessage.idImg
                this.dataForm.certificate = data.doctorMessage.certificate
                this.dataForm.licence = data.doctorMessage.licence
                this.dataForm.tel = data.doctorMessage.tel
                this.dataForm.status = data.doctorMessage.status
                this.dataForm.reason = data.doctorMessage.reason
                this.dataForm.goodDegree = data.doctorMessage.goodDegree
                this.dataForm.idCard = data.doctorMessage.idCard
                this.dataForm.totalMoney = data.doctorMessage.totalMoney
                this.dataForm.year = data.doctorMessage.year
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/doctor/doctormessage/${!this.dataForm.doctorId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'doctorId': this.dataForm.doctorId || undefined,
                'doctorName': this.dataForm.doctorName,
                'hospitalId': this.dataForm.hospitalId,
                'doctorGrade': this.dataForm.doctorGrade,
                'idImg': this.dataForm.idImg,
                'certificate': this.dataForm.certificate,
                'licence': this.dataForm.licence,
                'tel': this.dataForm.tel,
                'status': this.dataForm.status,
                'reason': this.dataForm.reason,
                'goodDegree': this.dataForm.goodDegree,
                'idCard': this.dataForm.idCard,
                'totalMoney': this.dataForm.totalMoney,
                'year': this.dataForm.year
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
